﻿@model IEnumerable<Citi.Scheduler.WebUi.Models.RoutineExecutionModel>
<script type="text/javascript">
    $(function () {
        $("[rel=tooltip]").tooltip({ placement: 'right' });
    });
</script>
<table class="table table-bordered table-striped">
    <tr>
        <th>
        </th>
        <th>
            Routine Name
        </th>
        @if (!ViewBag.TopExecutions)
        {
            <th>
                Responsible
            </th>
        }
        <th>
            Status (Last Update)
        </th>
        <th>
        </th>
    </tr>
    @if (Model == null || !Model.Any())
    {
        <tr>
            <td colspan="4">
                No executions to show
            </td>
        </tr>
    }
    else
    {
        foreach (var item in Model)
        {
        <tr>
            <td style="text-align: center;">
                <span rel="tooltip" title="@item.Status.GetDescription()">
                    <img src="@Url.Content(string.Format("~/Content/Images/RoutineExecutionStatus/{0}.png", item.Status))" style="width:17px" alt="@item.Status.GetDescription()" />
                </span>
            </td>
            <td>
                @item.Routine.Name
            </td>
            @if (!ViewBag.TopExecutions)
            {
                <td>@item.Routine.User.Name
                </td>
            }
            <td>
                @item.RoutineExecutionHistories.Last().Status.GetDescription()
                (@(item.EndsOn.HasValue ? item.EndsOn.Value.ToString("yyyy/MM/dd HH:mm") : item.ScheduledDateTime.ToString("yyyy/MM/dd HH:mm")))
            </td>
            <td>
                @Html.ActionLink("Details", "Index", "RoutineExecutionHistory", new { routineExecutionId = item.Id }, new { @class = "icon-eye-open" })
                @*@if (!ViewBag.TopExecutions)*@
                @*{*@
                    @Ajax.ActionLink("Re-run", "Create", "RoutineOnDemand", new { routineId = item.Routine.Id },
                    new AjaxOptions
                    {
                        Confirm = string.Concat("This routine will be executed when some machine becomes available or if the routine has a specific machine, when this machine becomes available. ",
                            "This action can not be canceled and if this routine is scheduled to execute today and it hasn't been executed yet, the scheduled routine will be canceled. Do you want to continue?")
                    },
                    new { @class = "icon-play", title = "Re-run" })
                @*}*@
            </td>
        </tr>
        }
    }
</table>
